package cn.com.bluemoon.daps.sync.entity;

import cn.com.bluemoon.daps.common.domain.BaseModel;
import cn.com.bluemoon.daps.common.enums.SyncStatus;
import cn.com.bluemoon.daps.common.enums.SyncToEnv;
import com.baomidou.mybatisplus.annotation.EnumValue;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

/**
 * <p>
 * 发布同步单号数据任务-明细表
 * </p>
 *
 * @author admin
 * @since 2021-06-17
 */
@Data
@Accessors
@ApiModel(value = "DapSyncProdEnvTaskDetail", description = "发布同步单号数据任务-明细表")
public class DapSyncProdEnvTaskDetail extends BaseModel<DapSyncProdEnvTaskDetail> {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "模型id")
    private String modelId;

    @ApiModelProperty(value = "模型表id")
    private String tableId;

    @ApiModelProperty(value = "模型表名")
    private String tableName;

    @ApiModelProperty(value = "发布同步单号数据任务表id")
    private String taskId;

    @ApiModelProperty(value = "一个表中所有变更的ddl脚本语句，英文分号隔开")
    private String ddl;

    @ApiModelProperty(value = "ddl脚本对应的pt语句，可执行的ptosc")
    private String ptOsc;

    @ApiModelProperty(value = "ddl脚本对应的pt语句，ptosc无法可执行的表级别ddl语句")
    private String ptDdl;

    @ApiModelProperty(value = "预发布脚本同步状态，0：未同步、1：同步中、2：已同步、3：同步失败、-1：沙箱同步中，其中0/1对应为未执行，而2/3对应为已执行，-1为沙箱环境中执行（区分预发布执行）", example = "0")
    @EnumValue
    private SyncStatus preProdScriptStatus;

    @ApiModelProperty(value = "预发布同步日志存储")
    private String preProdSyncLog;

    @ApiModelProperty(value = "生产脚本同步状态，0：未同步、1：同步中、2：已同步、3：同步失败、-1：沙箱同步中，其中0/1对应为未执行，而2/3对应为已执行，-1为沙箱环境中执行（区分预发布执行）", example = "0")
    @EnumValue
    private SyncStatus prodScriptStatus;

    @ApiModelProperty(value = "生产同步日志存储")
    private String prodSyncLog;

    @ApiModelProperty(value = "发布同步处于同步中的日志路径")
    private String syncLogPath;

    @ApiModelProperty(value = "执行脚本的完整语句")
    private String syncScript;

    @ApiModelProperty(value = "同步管理中-是否需要DBA介入，1是，0否")
    private Boolean needDba;

    @ApiModelProperty(value = "同步管理中-修改状态的DBA")
    private String dbaManageBy;

    @ApiModelProperty(value = "同步管理中-修改状态的处理时间")
    private String dbaManageTime;

    @ApiModelProperty(value = "同步管理中-同步生产-修改状态时刻的表结构记录")
    private String syncProdPreTbSql;

    @ApiModelProperty(value = "同步管理中-同步预发布-修改状态时刻的表结构记录")
    private String syncPreProdPreTbSql;

    @ApiModelProperty(value = "同步管理中-同步生产-DBA实际执行的DDL记录")
    private String realSyncProdDdl;

    @ApiModelProperty(value = "同步管理中-同步预发布-DBA实际执行的DDL记录")
    private String realSyncPreProdDdl;

    /**
     * 用于判断沙箱环境失败情况下，发布同步预览的表脚本都归为未执行
     */
    @ApiModelProperty(value = "是否为执行沙箱环境失败，0否 1是，默认为0")
    private Boolean sandboxSyncFail;

    @ApiModelProperty(hidden = true)
    public void setSyncPreTbSql(String preTbSql, SyncToEnv syncToEnv){
        if (syncToEnv == null) {
            return;
        }
        if (preTbSql == null) {
            return;
        }
        if (SyncToEnv.PROD.equals(syncToEnv)) {
            setSyncProdPreTbSql(preTbSql);
        }
        if (SyncToEnv.PRE_PROD.equals(syncToEnv)) {
            setSyncPreProdPreTbSql(preTbSql);
        }
    }

    @ApiModelProperty(hidden = true)
    public String getSyncPreTbSql(SyncToEnv syncToEnv){
        if (SyncToEnv.PROD.equals(syncToEnv)) {
            return this.syncProdPreTbSql;
        }
        if (SyncToEnv.PRE_PROD.equals(syncToEnv)) {
            return this.syncPreProdPreTbSql;
        }
        return null;
    }


    @ApiModelProperty(hidden = true)
    public void setRealSyncDdl(String realSyncProdDdl, SyncToEnv syncToEnv){
        if (syncToEnv == null) {
            return;
        }
        if (realSyncProdDdl == null) {
            return;
        }
        if (SyncToEnv.PROD.equals(syncToEnv)) {
            setRealSyncProdDdl(realSyncProdDdl);
        }
        if (SyncToEnv.PRE_PROD.equals(syncToEnv)) {
            setRealSyncPreProdDdl(realSyncProdDdl);
        }
    }

    @ApiModelProperty(hidden = true)
    public String getRealSyncDdl(SyncToEnv syncToEnv){
        if (SyncToEnv.PROD.equals(syncToEnv)) {
            return this.realSyncProdDdl;
        }
        if (SyncToEnv.PRE_PROD.equals(syncToEnv)) {
            return this.realSyncPreProdDdl;
        }
        return null;
    }


    @ApiModelProperty(hidden = true)
    public void setSyncLog(String syncLog, SyncToEnv syncToEnv){
        if (syncToEnv == null) {
            return;
        }
        if (syncLog == null) {
            return;
        }
        if (SyncToEnv.PROD.equals(syncToEnv)) {
           setProdSyncLog(syncLog);
        }
        if (SyncToEnv.PRE_PROD.equals(syncToEnv)) {
            setPreProdSyncLog(syncLog);
        }
    }

    @ApiModelProperty(hidden = true)
    public String getSyncLog(SyncToEnv syncToEnv){
        if (SyncToEnv.PROD.equals(syncToEnv)) {
            return this.prodSyncLog;
        }
        if (SyncToEnv.PRE_PROD.equals(syncToEnv)) {
            return this.preProdSyncLog;
        }
        return null;
    }

    @ApiModelProperty(hidden = true)
    public void setScriptSyncStatus(SyncStatus syncStatus, SyncToEnv syncToEnv){
        if (syncToEnv == null) {
            return;
        }
        if (syncStatus == null) {
            return;
        }
        if (SyncToEnv.PROD.equals(syncToEnv)) {
            setProdScriptStatus(syncStatus);
        }
        if (SyncToEnv.PRE_PROD.equals(syncToEnv)) {
            setPreProdScriptStatus(syncStatus);
        }
    }

    @ApiModelProperty(hidden = true)
    public SyncStatus getScriptSyncStatus(SyncToEnv syncToEnv){
        if (SyncToEnv.PROD.equals(syncToEnv)) {
            return this.prodScriptStatus;
        }
        if (SyncToEnv.PRE_PROD.equals(syncToEnv)) {
            return this.preProdScriptStatus;
        }
        return null;
    }
}
